package com.zgz.park.controller;

import com.zgz.park.common.config.Result;
import com.zgz.park.pojo.User;
import com.zgz.park.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author zhangguozhuang
 * @Date 2022/12/11
 */
@CrossOrigin
@RestController
@RequestMapping("/park")
public class LoginController {

    @Resource
    private UserService userServiceImpl;

    @PostMapping("/login")
    public Result login(@RequestBody User user ){
        User loginUser = userServiceImpl.login(user.getUserName(),user.getPassword());
        if(loginUser != null){
            Map<String,Object> map = new HashMap<>();
            map.put("user", loginUser);
            map.put("token","admin");
            return Result.succ().message("登录成功").data(map);

        }
        return Result.error().message("登录失败");
    }

    @GetMapping("/getUserInfo")
    public Result getUserInfo(){
        return Result.succ()
                .data("roles","admin")
                .data("name","admin")
                .data("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
    }
}
